/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.gemom.auction;

import com.gemom.*;
import java.util.*;
/**
 *
 * @author Yair Diaz
 */
public class BidGenerator {
    
    //items to be added: numberitems/2 maximum; this improves my analysis
    //for testing purposes this shows much better how the search behaves
    
    public Vector<Bid> getListBidsGen(int numberitems,int numberbids, double avgprice){
	
            int[]itemstoAdd=new int[numberitems];
             for(int i=0;i<itemstoAdd.length;i++)itemstoAdd[i]=0;
        
            
                //generation of the item array
               Item[] arrayItems= new Item[numberitems];
               for(int i=0;i<arrayItems.length;i++)
                     arrayItems[i] = new Item(i,0.0,0.0,0.0);//itemrate zero for now
                
		//Generates the items ;and generates the number of items per bid
		Random genItem = new Random();
		//Generating the price
		Random genPrice = new Random();
		
		//Generating the bids		
		Vector<Bid> listBids = new Vector<Bid>();
			for(int i=0;i<numberbids;i++)
				listBids.add(new Bid(i));
                
			
		//Adding items to each bid (randomly)
		int ripb=0;
		for(int i=0;i<listBids.size();i++){
			//number of iterations to add items. 1 is added to avoid a bid with no items
			ripb = genItem.nextInt( (numberitems/2)+1 );//number of items to be added: random
			if(ripb==0)ripb=1;
			for(int j=0;j<ripb;j++)itemstoAdd[genItem.nextInt( numberitems)]=1;
                    
                        //checking for repeated items in the same bid lol!!!         
                   for(int g=0;g<itemstoAdd.length;g++)         
                         if(itemstoAdd[g]==1)listBids.get(i).addItem(arrayItems[g]);
	      
                    for(int p=0;p<itemstoAdd.length;p++)itemstoAdd[p]=0;
    		//checking for repeated bids
				int sum=0;	
				for(int k=0;k<listBids.size();k++){
					sum=0;
                                        //down here it checks first the number of items in current bid against other bids
					if(listBids.get(i).getItemsVec().size()==listBids.get(k).getItemsVec().size() && k!=i && listBids.get(k).getItemsVec().size()!=0)
						for(int l=0;l<listBids.get(i).getItemsVec().size();l++){
							if(listBids.get(i).getItemsVec().get(l).getItemID()== listBids.get(k).getItemsVec().get(l).getItemID())
								{sum+=1;}
						}//end-for
				
                               if(sum==listBids.get(i).getItemsVec().size())
                                    {for(int h=0;h<numberitems;h++)listBids.get(i).getItemsVec().removeAllElements() ;--i;}	
				}//end-for
		}//end-for                           
	
               //setting the price for each bid
		for(int i=0;i<listBids.size();i++){
			
			for(int j=0;j<listBids.get(i).getItemsVec().size();j++)
				listBids.get(i).price+= (avgprice/2)*genPrice.nextDouble()+0.75*avgprice;
		}	
		
		//adding dummy bids
		int[]check=new int[numberitems];
		for(int i=0;i<check.length;i++)check[i]=0;
                
		for(int j=0;j<listBids.size();j++){
			if(listBids.get(j).getItemsVec().size()==1)
				check[listBids.get(j).getItemsVec().get(0).getItemID()]=1;}
		
		
			for(int i=0;i<check.length;i++){
			if(check[i]==0){listBids.add(new Bid(listBids.size()+1+i));
				            listBids.lastElement().addItem(arrayItems[i]);}
				            }
                
         //////////////////////////////////////////////////////////////////////

            //    for(int j=0;j<listBids.size();j++)
            //        System.out.println(listBids.get(j).getItemsVec().size() +"   "+listBids.get(j).price);
                
		return listBids;


    }
    
}
